/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package consumo.face;

import java.io.BufferedReader;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import memMassa.TabulaArquivo;
import memMassa.conjuntos.MemMassa;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;

/**
 *
 * @author Carlos Taschetto
 */
@Named
@SessionScoped
public class ImportarMemMassaFaces extends BaseCDIBean{

    private static final long serialVersionUID = 16L;
    //private File arq;


    public void getFileUpload(FileUploadEvent event){
        //logger.info("Uploaded: {}", event.getFile().getFileName());
        try{
            System.out.println(System.getProperty("user.dir"));
        UploadedFile file = event.getFile();
        byte[] readData = file.getContents();
        String array = new String(readData);
        BufferedReader br = new BufferedReader(new StringReader(array));

        TabulaArquivo mm = new TabulaArquivo();
        mm.setBuffers(br);
        List<MemMassa> listagem = mm.getListagem();
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        System.out.println("Data    Ph  kW  kVAri   kVARc   FP  FER");
        for(MemMassa val:listagem){
            System.out.println(sdf.format(val.getHora())+"  "+val.getPh()+" "+
                    val.getCanal1()+" "+val.getCanal2()+"   "+val.getCanal3()+" "+
                    val.getFatPot()/100.0+"   "+val.getFer()+"       "+val.getSr());
        }
        }catch(Exception e ){
            e.printStackTrace();
        }

    }

}
